/*
 * @LastEditTime: 2023-03-16 20:52:45
 * @Method: 快速排序
 * @Description: 
 */
package AcWing;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;

public class Solution785 {
    public static void quickSort(int[] nums, int l, int r) {
        if (l >= r) {
            return;
        }
        int m = partition(nums, l, r);
        quickSort(nums, l, m - 1);
        quickSort(nums, m + 1, r);
        return;
    }

    public static int partition(int[] nums, int l, int r) {
        if (l > r) {
            return -1;
        }
        if (l == r) {
            return l;
        }
        int randNum = l + new Random().nextInt(r - l);
        swap(nums, randNum, r);
        int index = l;
        int pivot = nums[r];
        for (int i = l;i < r;i++) {
            if (nums[i] < pivot) {
                swap(nums, index, i);
                index++;
            }
        }
        swap(nums, index, r);
        return index;
    }

    public static void quickSort2 (int[] nums) {
        Stack<Integer> s = new Stack<>();
        s.push(nums.length - 1);
        s.push(0);
        while (!s.isEmpty()) {
            int l = s.pop();
            int r = s.pop();
            if (l >= r) {
                continue;
            }
            int m = partition(nums, l, r);
            s.push(m - 1);
            s.push(l);
            s.push(r);
            s.push(m + 1);
        }
    }

    public static void swap (int[] nums, int i, int j) {
        int t = nums[j];
        nums[j] = nums[i];
        nums[i] = t;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int[] nums = new int[m];
        for (int i = 0;i < m;i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        // quickSort(nums, 0, nums.length - 1);
        quickSort2(nums);
        for (int i = 0;i < nums.length;i++) {
            System.out.print(nums[i]);
            if (i != nums.length - 1) {
                System.out.print(" ");
            }
        }
    }
}
